package com.wlyuan.index.api.dto.waybill;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.wlyuan.index.api.dto.Versioned;
import com.wlyuan.transport.dto.QuoteFeeDetailDTO;
import com.wlyuan.transport.dto.WaybillPriceDetailDTO;
import com.wlyuan.transport.dto.common.AttachmentDTO;
import com.wlyuan.transport.dto.common.LocationDTO;
import com.wlyuan.transport.dto.common.WaybillCacheDTO;
import com.wlyuan.transport.dto.query.*;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yuanjie
 */
@Data
public class WaybillIndexDTO implements Versioned, Serializable {
    @ApiModelProperty("订单ID")
    private Long orderId;

    @ApiModelProperty("运单ID")
    private Long waybillId;

    @ApiModelProperty("合同号")
    private String contractNo;

    @ApiModelProperty("合单id")
    private Long combineId;

    @ApiModelProperty("合单编号")
    private String combineNo;

    @ApiModelProperty("合单合同号")
    private String combineContractNo;

    @ApiModelProperty("是否被合单")
    private Boolean combined;

    @ApiModelProperty("是否被拆单")
    private Boolean divided;

    @ApiModelProperty("备注")
    private String desc;

    @ApiModelProperty("发货时间")
    private LocalDateTime fromTime;

    @ApiModelProperty("发货方信息")
    private WaybillCustomerDTO customer;

    @ApiModelProperty("发货方联系人")
    private WaybillContact fromContact;

    @ApiModelProperty("发货地址")
    private LocationDTO fromAddress;

    @ApiModelProperty("收货方信息")
    private WaybillConsigneeDTO consignee;

    @ApiModelProperty("收货地址")
    private LocationDTO toAddress;

    @ApiModelProperty("收货方联系人")
    private WaybillContact toContact;

    @ApiModelProperty("收货时间")
    private LocalDateTime toTime;

    @ApiModelProperty("承运方信息")
    private WaybillCarrierDTO carrier;

    @ApiModelProperty("提货预约")
    private WaybillPickCovenantDetailDTO pickCovenant;

    @ApiModelProperty("运输要求")
    @JSONField(alternateNames = "transportRequirement")
    private WaybillArgumentsDTO arguments;

    @ApiModelProperty("设备信息")
    private DeviceDetailDTO device;

    @ApiModelProperty("运单缓存信息")
    private WaybillCacheDTO waybillCache;

    @ApiModelProperty("运单附件")
    private List<AttachmentDTO> attachments;

    @ApiModelProperty("创建时间")
    private LocalDateTime createAt;

    @ApiModelProperty("创建人")
    private UserDTO createBy;

    @ApiModelProperty("更新时间")
    private LocalDateTime updateAt;

    @ApiModelProperty("修改人")
    private UserDTO updateBy;

    @ApiModelProperty("调度时间")
    private LocalDateTime dispatchAt;

    @ApiModelProperty("调度人")
    private UserDTO dispatchBy;

    @ApiModelProperty(value = "租户ID")
    private Long tenantId;

    @ApiModelProperty(value = "关账状态 0：未关账，1已关账")
    private Integer billDayStatus;

    @ApiModelProperty(value = "关账状态描述")
    private String billDayStatusDesc;

    @ApiModelProperty("关单信息")
    private CloseDetailDTO close;

    @ApiModelProperty("关单状态 10撤回中, 20待审核, 30拒绝中,40拒绝,50关单中，60同意")
    private Integer closeStatus;

    @ApiModelProperty("关单状态描述")
    private String closeStatusDesc;

    @ApiModelProperty("运单费用")
    private WaybillPriceDetailDTO waybillPrice;

    @ApiModelProperty("运单财务信息")
    private WaybillFinanceDTO finance;

    @ApiModelProperty(value = "发货方(上游)")
    WaybillRelationEventDTO upstream;

    @ApiModelProperty(value = "承运方(下游)")
    WaybillRelationEventDTO downstream;

    @ApiModelProperty("是否需要费用：0否，1是")
    private Boolean needFee;

    @ApiModelProperty("是否从单")
    private Boolean followWaybill;

    @ApiModelProperty("是否原始运单 1：是,0:否")
    private Integer isRootWaybill;

    @ApiModelProperty("版本号")
    private Long version;

    @ApiModelProperty("订单状态")
    private Integer orderStatus;

    @ApiModelProperty("订单状态desc")
    private String orderStatusDesc;

    @ApiModelProperty("订单编号")
    private String orderNo;

    @ApiModelProperty("运输状态 1提货中,2已发货,3已到达,4已签收")
    private Integer transportStatus;

    @ApiModelProperty("运输状态描述")
    private String transportStatusDesc;

    @ApiModelProperty("报价申请")
    private QuoteFeeDetailDTO quoteFee;

    @ApiModelProperty("扩展信息")
    private JSONObject echo;

    @ApiModelProperty("延期时间 单位分钟")
    private Long delayTime;

    @ApiModelProperty("合单状态 10 待调度 20 已委托 21 接收中 30 已完成 40 已关闭")
    private Integer combineStatus;

    @ApiModelProperty("是否是拆单子单")
    private Boolean childWaybill;

    @ApiModelProperty("是否已接收")
    private Boolean accepted;

    @ApiModelProperty("是否可以提货预约")
    private Boolean showPickCovenant;

    @ApiModelProperty("是否签收延迟")
    private Boolean signDelayed;

    @ApiModelProperty("是否签收延迟")
    private String signDelayedDesc;

    @ApiModelProperty("是否延迟")
    private Boolean isDelayed;

    @ApiModelProperty("是否开通报价权限")
    private Boolean quoteAuthority;

    @ApiModelProperty("是否开通财务权限")
    private Boolean financeAuthority;

    public Boolean getHasFees() {
        return null != this.getWaybillPrice() && null != this.getWaybillPrice().getQuotationStatus();
    }
}
